home *** CD-ROM | disk | FTP | other *** search
- Path: corona.laa.com.au!news
- From: Jason Collins <jason@www.inia.net.au>
- Newsgroups: comp.lang.c
- Subject: read/write integers to files
- Date: Thu, 07 Mar 1996 20:50:13 +1000
- Organization: Internet Image
- Message-ID: <313EBF65.4E82@www.inia.net.au>
- NNTP-Posting-Host: inia-a04.laa.com.au
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Hi there,
-
- I would preface this question with the standard "dumb newbie question......." or whatever but I
- think you'll work it out for yourselves soon enough.
-
- My problem is that I'm trying to write a program that will read an integer from the file
- count.dat, increment the integer then write it back to count.dat. I have provided the listing so
- that you can all tell me what I'm doing wrong.
-
- Thanks....and.....be gentle.
-
- --------------------
- counter.c
- --------------------
-
- #include <stdio.h>
- #include <stdlib.h>
-
- FILE *filePtr;
-
- void main()
- {
- char ctr;
-
- filePtr=fopen("count.dat", "ab");
- fscanf(filePtr, "%d", &ctr);
- fclose(filePtr);
-
- ctr++;
-
- filePtr=fopen("count.dat", "wb");
- fprintf(filePtr, "%d", ctr);
- fclose(filePtr);
- }
-